package com.beyond.trace.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.beyond.trace.domain.TraceLand;
import com.beyond.trace.service.ITraceLandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地块信息Controller
 * 
 * @author yao
 * @date 2022-03-02
 */
@RestController
@RequestMapping("/trace/land")
@Api(value = "地块信息", tags = "地块信息")
public class TraceLandController extends BaseController
{
    @Autowired
    private ITraceLandService traceLandService;

    //@PreAuthorize("@ss.hasPermi('beyond:land:list')")
    @GetMapping("/list")
    @ApiOperation("查询地块信息列表")
    public TableDataInfo list(TraceLand traceLand)
    {
        startPage();
        List<TraceLand> list = traceLandService.selectTraceLandList(traceLand);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('beyond:land:query')")
    @GetMapping(value = "/query")
    @ApiOperation("查询地块信息列表不分页")
    public AjaxResult getInfoQuery(TraceLand traceLand)
    {
        return AjaxResult.success(traceLandService.selectTraceLandList(traceLand));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:land:export')")
    @Log(title = "地块信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceLand traceLand)
    {
        List<TraceLand> list = traceLandService.selectTraceLandList(traceLand);
        ExcelUtil<TraceLand> util = new ExcelUtil<TraceLand>(TraceLand.class);
        return util.exportExcel(list, "地块信息数据");
    }

    //@PreAuthorize("@ss.hasPermi('beyond:land:query')")
    @GetMapping(value = "/{landId}")
    @ApiOperation("查询地块信息列表")
    public AjaxResult getInfo(@PathVariable("landId") Long landId)
    {
        return AjaxResult.success(traceLandService.selectTraceLandById(landId));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:land:add')")
    @Log(title = "地块信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增地块信息")
    public AjaxResult add(@RequestBody @Validated TraceLand traceLand)
    {
        return toAjax(traceLandService.insertTraceLand(traceLand));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:land:edit')")
    @Log(title = "地块信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改地块信息")
    public AjaxResult edit(@RequestBody TraceLand traceLand)
    {
        return toAjax(traceLandService.updateTraceLand(traceLand));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:land:remove')")
    @Log(title = "地块信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{landIds}")
    @ApiOperation("删除地块信息")
    public AjaxResult remove(@PathVariable Long[] landIds)
    {
        return toAjax(traceLandService.deleteTraceLandByIds(landIds));
    }
}
